<template>
  <div>
    <button-v :to="'/my/collectionShop'"  :text="'商品收藏'"></button-v>
    <button-v :to="'/my/collectionStore'" :text="'收藏店铺'"></button-v>
    <!--暂无数据  -->
    <div v-if="favoriteList.length == 0 || !favoriteList">
      <div class="bgImg"></div>
    </div>
    <!--收藏数据不为空  -->
    <div class="content" v-else>
      <div class="goodsItem" v-for="(goodsInfo, index) in favoriteList" :key="index">
        <goods-item :goods-info="goodsInfo" :theme="4"></goods-item>
      </div>
      <div class="clear"></div>
      <div v-if="totalPage > 1">
        <w-paging :total="totalPage" @on-page="onPage"></w-paging>
      </div>
    </div>
  </div>
</template>
<script>
import buttonV from './components/Button.vue'
import goodsItem from './../search/components/GoodsItem'
import { apiSelectFavoriteAll } from 'js/api'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      favoriteList: [],
      // 当前页
      currentPage: 1,
      // 一页显示
      showCount: 15,
      // 总页数
      totalPage: 1
    }
  },
  components: {
    buttonV,
    goodsItem
  },
  created() {
    this.getFavoriteAll()
  },
  computed: {
    ...mapGetters(['token'])
  },
  methods: {
    // 请求收藏商品接口
    getFavoriteAll() {
      apiSelectFavoriteAll(this.token, this.currentPage, this.showCount).then((data) => {
        this.favoriteList = data.favoriteList
        this.totalPage = data.totalPage
      })
    },
    // 点击下一页
    onPage(index) {
      this.currentPage = index
      this.getFavoriteAll()
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '../../scss/_var.scss';
  .bgImg {
    background-image: url(../../assets/nullIcon/icon_collection.png);
    margin: 50px auto auto;
    width: 310px;
    height: 270px;
    background-repeat: no-repeat;
    text-align: center;
    background-size: contain;
    background-position: 50% 50%;
  }
  .content {
    // width: 850px;
    padding: 20px 50px;
    background-color: $color-white;
    margin-top: 10px;
  }
  .goodsItem {
    float: left;
    margin-right: 19px;
    margin-bottom: 19px;
    &:nth-child(5n+5) {
        margin-right: 0;
    }
  }
  .clear {
    clear: both;
  }
</style>